package container

import (
	"context"
	"fmt"
	"github.com/docker/docker/api/types"
	"github.com/docker/docker/client"
	"log"
)

func NewDocker() *Docker {
	cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
	if err != nil {
		log.Fatal(err)
	}

	return &Docker{
		client: cli,
	}
}

type Docker struct {
	client *client.Client
}

func (r *Docker) StartInstance(containerID string) error {
	fmt.Println("Starting Docker container:", containerID)
	return r.client.ContainerStart(context.Background(), containerID, types.ContainerStartOptions{})
}
func (r *Docker) StopInstance(containerID string) error {
	fmt.Println("Stopping Docker container:", containerID)
	return r.client.ContainerStop(context.Background(), containerID, nil)
}
func (r *Docker) RestartInstance(containerID string) error {
	fmt.Println("Restarting Docker container:", containerID)
	return r.client.ContainerRestart(context.Background(), containerID, nil)
}
